<?php
namespace addon\mall\controller;
use app\common\controller\AddonAdminBase;
use tpfcore\Core;
// +----------------------------------------------------------------------
// | Author: yaoyihong <510974211@qq.com>
// +----------------------------------------------------------------------
/**
 * ============================================================================
 * 版权所有 2017-2077 tpframe工作室，并保留所有权利。
 * @link http://www.tpframe.com/
 * @copyright Copyright (c) 2017 TPFrame Software LLC
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！未经本公司授权您只能在不用于商业目的的前提下对程序代码进行修改和使用；
 * 不允许对程序代码以任何形式任何目的的再发布
 * ============================================================================
 */
class AccountLog extends AddonAdminBase
{
    public function index(){
      $data=$search = $this->param;
      $this->assign('search',$search);
      $where=[];
      if(!empty($data['user'])){
        is_numeric($data['user'])?$where['__USER__.id']=$data['user']:$where['__USER__.username']=$data['user'];  
      }
      $begin='';$end='';
      !empty($data['start_time']) ? $begin=strtotime($data['start_time']) : '';
      empty($data['end_time']) ? $end=time() : $end=strtotime($data['end_time']);
      if($begin && $end){
        $where['__ACCOUNT_LOG__.change_time'] = ['between',"$begin,$end"];
      }
      if(!empty($data['order_sn'])){
        $where['order_sn']=$data['order_sn'];
      }

      $list = Core::loadAddonModel("AccountLog")->getAccountLog([
          "where"=>$where,
          "field"=>"__ACCOUNT_LOG__.*,__USER__.username",
          "join"=>["join"=>"__USER__","condition"=>"__ACCOUNT_LOG__.user_id=__USER__.id","type"=>"left"],
          "order"=>"__ACCOUNT_LOG__.change_time desc",
          'paginate'=>['rows' =>20,"config"=>["query"=>$this->param]],
      ]);

    	$this->addonTemplate('index',[
        "list"=>$list
    	]);
    }
}